package com.flyan.game.motafx.event;

import com.almasb.fxgl.dsl.FXGL;
import com.flyan.game.motafx.core.event.BaseEvent;
import com.flyan.game.motafx.core.event.enums.EventTypeEnum;
import javafx.util.Duration;

/**
 * 游戏休眠
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/12
 */
public class GameSleepEvent extends BaseEvent {

    @Override
    public String type() {
        return EventTypeEnum.GAME_SLEEP.getCode();
    }

    @Override
    public void occur() {
        if (duration() != Duration.ZERO) {
            FXGL.set("game:sleep", true);
            FXGL.runOnce(() -> FXGL.set("game:sleep", false), duration());
        }
    }

}
